package com.ibeetl.admin.console.service.stat;

import com.ibeetl.admin.console.dao.stat.BackChargeStatDao;
import com.ibeetl.admin.console.dao.stat.CoinStatDao;
import com.ibeetl.admin.console.web.dto.BackChargeExcelData;
import com.ibeetl.admin.console.web.dto.PayOrderExcelExportData;
import com.ibeetl.admin.core.entity.PayOrder;
import com.ibeetl.admin.core.entity.stat.BackChargeStat;
import com.ibeetl.admin.core.entity.stat.CoinStat;
import com.ibeetl.admin.core.entity.stat.ReportStat;
import com.ibeetl.admin.core.service.BaseService;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class BackChargeStatService extends BaseService<ReportStat> {

	@Autowired
	BackChargeStatDao backChargeStatDao;

	/**
	 * 根据条件查询
	 *
	 * @param query
	 */
	public void queryByCondtion(PageQuery<BackChargeStat> query) {
		PageQuery<BackChargeStat> ret = backChargeStatDao.queryByCondtion(query);
		queryListAfter(ret.getList());
	}


    public List<BackChargeExcelData> queryExcel(PageQuery<BackChargeStat> query) {
		PageQuery<BackChargeStat> ret = backChargeStatDao.queryByCondtion(query);
		List<BackChargeStat> list = ret.getList();
		List<BackChargeExcelData> items = new ArrayList<>();

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		for(BackChargeStat backChargeStat:list) {
			BackChargeExcelData backChargeExcelData = new BackChargeExcelData();
			backChargeExcelData.setOpenid(backChargeStat.getOpenid());
			backChargeExcelData.setNickname(backChargeStat.getNickname());
			backChargeExcelData.setOrderNo(backChargeStat.getOrderNo());
			backChargeExcelData.setAmount(backChargeStat.getAmount());
			backChargeExcelData.setScore(backChargeStat.getScore());
			backChargeExcelData.setGiftScore(backChargeStat.getGiftScore());
			backChargeExcelData.setCreator(backChargeStat.getCreator());
			backChargeExcelData.setCreateTime(sdf.format(backChargeStat.getCreateTime()));
			backChargeExcelData.setUserChargeAmount(backChargeStat.getUserChargeAmount());
			if(null!=backChargeStat.getUserChargeTime()){
				backChargeExcelData.setUserChargeTime(sdf.format(backChargeStat.getUserChargeTime()));

			}

			items.add(backChargeExcelData);

		}
		return items;
    }
}
